function err = shift_overlap(x)

% x(1) is shift, x(2) is scale
% err is deviation between the resulting curves

global fitdata1 fitdata2 fitwindow
ind1 = fitdata1(:,1)>=fitwindow(1) & fitdata1(:,1)<=fitwindow(2);
freq = fitdata1(ind1,1);
data2 = interp1(fitdata2(:,1)+x(1),x(2)*fitdata2(:,2),freq);
err = sum((fitdata1(ind1,2)-data2).^2)/length(freq);    % normalize by no. of points